package com.example.admin.yuejian21.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;

import com.example.admin.yuejian21.Adapter.PicAdapter;
import com.example.admin.yuejian21.Adapter.RenqiAdapter;
import com.example.admin.yuejian21.Bean.Club;
import com.example.admin.yuejian21.Bean.Pic;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.Service.Service;
import com.example.admin.yuejian21.activity.ReleaseActivity;
import com.example.admin.yuejian21.activity.yjActivity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class StFragment extends Fragment {
    private RecyclerView recyclerView;

    private PicAdapter adapter;
    private List<Pic> Piclist;
    private String SessionID="060pn7sjorpnq5fp53kid5st54";
    private ImageButton button;

    public StFragment() {

    }
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        recyclerView =
                (RecyclerView) view.findViewById(R.id.recyclerView1);
        button= (ImageButton) view.findViewById(R.id.imageButton_fabusaitu);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), ReleaseActivity.class);
                startActivity(intent);
            }
        });
    }

<<<<<<< HEAD

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        Retrofit retrofit=new Retrofit.Builder().baseUrl("http://172.24.10.175/workout/api.php/").addConverterFactory(GsonConverterFactory.create())
                .build();
        Service service=retrofit.create(Service.class);
        Call<List<Pic>> call=service.showpic(SessionID);
        call.enqueue(new Callback<List<Pic>>() {
            @Override
            public void onResponse(Call<List<Pic>> call, Response<List<Pic>> response) {
                if(getActivity()!=null) {
                    Piclist = response.body();
                    adapter = new PicAdapter(getActivity(), Piclist);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
                    linearLayoutManager.setOrientation(linearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(linearLayoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                }

            }

            @Override
            public void onFailure(Call<List<Pic>> call, Throwable t) {

            }
        });


        return inflater.inflate(R.layout.fragment_st, container, false);
    }
=======
>>>>>>> 2e6d2ff2e3331c5e86ecd66212336d2d1a6d7e80

}
